//
// Created by Administrator on 2025/4/14/周一.
//
#include "iostream"

using namespace std;


int &test01() {
    int a = 10; //局部变量
    return a;
}

//返回静态变量引用
int &test02() {
    static int a = 20;
    return a;
}

int test03() {
    return 10;
}


int main() {


//    不能返回局部变量的引用
//    int &ref = test01();
//    cout << "ref = " << ref << endl;
//    cout << "ref = " << ref << endl;

    //如果函数做左值，那么必须返回引用
    int &ref2 = test02();
    cout << "ref2 = " << ref2 << endl;
    cout << "ref2 = " << ref2 << endl;

    test02() = 1000;
//    test03() = 100;如果返回的一直
    cout << "ref2 = " << ref2 << endl;
    cout << "ref2 = " << ref2 << endl;
}
